package pers.ree.demo.generic;

import java.util.ArrayList;

public class GenericDemo {

    public static void main(String[] args) {
        System.out.println(add(0.1, 0.05));
//        Number n = new Number();

        //
        ArrayList<Object> objList = new ArrayList<>();
        testSuper(objList);

        ArrayList<Number> numberList = new ArrayList<>();
        testSuper(numberList);

        ArrayList<Integer> intList = new ArrayList<>();
//        testSuper(intList); // 编译报错
    }

    private static <T extends Number> double add(T a, T b) {
        double d = a.doubleValue() + b.doubleValue();
        return d;
    }

    private static void testSuper(ArrayList<? super Number> list) {
        list.add(new Integer(1234));
        list.add(new Double(0.4321));
    }
}
